/*
 * @Author: linZeJian
 * @Date: 2022-01-27 15:47:50
 * @LastEditors: linZeJian
 * @LastEditTime: 2022-02-23 11:14:37
 * @Description: 
 */
import { createRouter, createWebHistory } from 'vue-router'
import Index from '../views/index.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'home',
      meta: { hidden: true, title: '首页' },
      component: Index
    },
    {
      path: '/about',
      name: 'about',
      // route level code-splitting
      // this generates a separate chunk (About.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () => import('../views/AboutView.vue')
    }
  ]
})

router.beforeEach((to:any, from:any, next:any) => {
  /* 路由发生变化修改页面title */
  if (to.meta.title) {
    // + ''   解决报错：不能将类型“unknown”分配给类型“string”。ts(2322)
    document.title = to.meta.title + ''
  }
  next()
})

export default router
